home *** CD-ROM | disk | FTP | other *** search
- Path: walt.tsc.com!not-for-mail
- From: billr@elmer.tsc.com (Bill Roberts)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: x ^= y ^= x ^= y;
- Date: 1 Mar 1996 12:22:45 -0500
- Organization: Technology Service Corporation
- Sender: Bill Roberts
- Message-ID: <4h7bp5$mf@elmer.tsc.com>
- References: <1286.6624T1439T237@cs.ruu.nl> <3131C523.1ECC@sapiens.com> <4h075l$2go@elmer.tsc.com> <2141.6632T1213T2220@cs.ruu.nl>
- NNTP-Posting-Host: elmer.tsc.com
-
- In article <2141.6632T1213T2220@cs.ruu.nl>,
- Wessel Dankers <wsldanke@cs.ruu.nl> wrote:
- !Bill Roberts <billr@elmer.tsc.com> wrote:
- !> What expression result will be in x at the end of the expression? The
- !> first one or the second one? The compiler may choose either. The c
- !No it definitely CAN'T choose!
- !The return value of an assignment is strictly documented and an ANSI feature!
- !
- But which experssion is stored, the first one calculated or the
- second? The C standard specifically says that the compiler may
- optimize the statement as it chooses. This problem is specifically
- discussed in the comp.lang.c FAQ's. The results are undefined. Your
- compiler may give you the result you expect. Another compiler may not.
- !The order is predefined: an assignment statement is of course right-
- !associative:
- !(x = y) = 4
- !has no meaning: how can you assign a value to a statement? A statement is no
- !lvalue.
- !x = (y = 4)
- !however, _is_ sensible.
- !
- As is x = y =4. However x += x += 4 is not. You have assigned two
- different values to x. You expect that 4 will be added to the current
- value of x, then that new value will replace the current value of x.
- Then the new value of x will be added to which value of x, the new
- value or the original value. Both are equally valid assumptions.
- Which did you want? Which did the compiler writer choose?
- x += ( x += 4 ); doesn't change the question.
-
- !> problem you will have with
- !> i = 1;
- !> x[ i++ ] = y[ i++ ];
- !> What will be the value of i at the end? And which value will be used
- !i++ means: increase i with one after using it. In this expression i is
- !increased twice in each pass.
- !while(d++ = s++);
- !for two arrays d[] and s[] (for each type) is valid, though.
- !
- Not the same problem. x++ is not the same as x[i++].
-
-